﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QDSpider.database;
using QDSpider.Models;

namespace QDSpider.manager
{
    public class ArticleAccountFetchHistoryManager
    {
        public static void Insert(ArticleAccountFetchHistory his)
        {
            using (var db=new S003Database())
            {
                var old =
                    db.SingleOrDefault<ArticleAccountFetchHistory>(
                        "select * from dyb_ArticleAccountFetchHistory where userid=@0 and account=@1 ", his.UserId,
                        his.Account);
                if (old == null)
                    db.Insert(his);
                else
                {
                    old.LastRequestTime = his.LastRequestTime;
                    db.Update(old);
                }
                    
            }
        }

        public static ArticleAccountFetchHistory Get(int userId, string account)
        {
            using (var db = new S003Database())
            {
                var old =
                    db.SingleOrDefault<ArticleAccountFetchHistory>(
                        "select * from dyb_ArticleAccountFetchHistory where userid=@0 and account=@1 ", userId,
                        account);
                return old;
            }
        }


    }
}
